﻿using DXApplicationTangche.UC.报表.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.报表
{
    public partial class Form抖音报表 : Form
    {
        public Form抖音报表()
        {
            InitializeComponent();
            this.gridControl1.DataSource = 抖音报表service.get备货();
            this.gridView1.RefreshData();

            this.gridControl2.DataSource = 抖音报表service.get已发货未到账();
            this.gridView2.RefreshData();

            this.gridControl3.DataSource = 抖音报表service.get每日发货明细();
            this.gridView3.RefreshData();

            this.gridControl4.DataSource = 抖音报表service.get每日收款到账();
            this.gridView4.RefreshData();

            this.gridControl5.DataSource = 抖音报表service.get每日未发货退货();
            this.gridView5.RefreshData();

            this.gridControl6.DataSource = 抖音报表service.get每日直播间成交明细();
            this.gridView6.RefreshData();

            this.gridControl7.DataSource = 抖音报表service.get每日销售全部订单();
            this.gridView7.RefreshData();

        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
            //dialog.Description = "请选择一个目录作为路径：";
            //dialog.ShowNewFolderButton = true;
            //System.Windows.Forms.DialogResult result = dialog.ShowDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string foldPath = dialog.SelectedPath;
                //MessageBox.Show("已选择文件夹:" + foldPath, "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //获取该目录下的文件
                string[] files = System.IO.Directory.GetFiles(@foldPath + "\\", "*.ini", System.IO.SearchOption.TopDirectoryOnly);
                String input = "";///字符串连接
                foreach (var f in files)
                {
                    String content  = GetContentByTxt(f);///引用
                    input += content;///字符串连接
                    //Console.WriteLine(f);
                }
                Form抖音报表.Writetxt(input);///引用
            }

        }

        /// <summary>
        /// 获取txt文件内容
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string GetContentByTxt(string path)
        {
            string conStr = "";
            try
            {
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                StreamReader reader = new StreamReader(fs);
                conStr = reader.ReadToEnd();///读取所有数据 ReadToEnd()，读取一行数据 ReadLine（）
            }
            catch (Exception)
            {
                conStr = "";
            }
            return conStr;
        }

        /// <summary>
        /// 文件内容写入
        /// </summary>
        /// <param name="path"></param>
        private static void Writetxt(string path)
        {
            System.IO.File.WriteAllText(@"D:\公司文件\抖音客户积累.txt", path);
        }
    }
}
